<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use App\model\Jinri;
use App\model\Project;

use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Layout\Row;
use Encore\Admin\Show;

class JinriController extends Controller
{
    use HasResourceActions;
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '头条项目设置';
    public function index(Content $content)
    {
        return $content
            ->header('头条项目设置')
            ->description('')
            ->body($this->grid());
    }
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Jinri());

        $grid->column('id', __('Id'));
        $grid->column('project.name', __(' 项目名称'));
        $grid->column('key', __('Key'));
        $grid->column('token', __('Token'));
        $grid->column('created_at', __('创建时间'));

        return $grid;
    }
    /**
     * Edit interface.
     *
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function edit($id, Content $content)
    {
        return $content
            ->header('编辑项目')
            ->description('')
            ->body($this->form()->edit($id));
    }
    /**
     * Create interface.
     *
     * @param Content $content
     * @return Content
     */
    public function create(Content $content)
    {
        return $content
            ->header('新增项目')
            ->description('')
            ->body($this->form());
    }
    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Jinri::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('key', __('Key'));
        $show->field('token', __('Token'));
        $show->field('project_id', __('Project id'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Jinri());

        $form->text('key', __('Key'))->rules('required');
        $form->text('token', __('Token'))->rules('required');
        $form->select('project_id','所属项目')->options(Project::getSelectOptions())->rules('required');

        return $form;
    }
}
